<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style1.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/form.js"></script>
<script type="text/javascript" language="javascript">
<!--
	function checkForm(){
		var objs = document.getElementsByName("id");
		var sign = 0;
		for(var i = 0; i < objs.length; i++){
			if(objs[i].value != 0 && objs[i].checked)sign = sign + 1;
		}
		if(sign <= 0){
			alert("<fmt:message key='myRecycle.message.select'/>");
			return false;
		}
		return true;
	}
	
	function personDialog(){
		var url = "./exceptionCustomer.do?action=preSelectPerson";
		var dlgParam = "dialogHeight:400px;dialogWidth:500px;dialogTop:300px;dialogLeft:400px;status:no;help:no;scrollbars:yes;";
		if(checkForm()){
			var rt = window.showModalDialog(url,"",dlgParam);
			if(rt != undefined && rt != ""){			
				//根据从子窗口得到销售负责人id,未使用个数,是否例外销售负责人
				var salePersonId = "";
				var notUseCustomerNum = "";
				var isExpUser = "";
				var tStr = rt.split(",");
				if(tStr[0] != "" && tStr[1] != ""){
					salePersonId += tStr[0];
					notUseCustomerNum += tStr[1];
				}
				isExpUser = tStr[2];
				
				var objs = document.getElementsByName("id");
				var sign = 0;
				for(var i = 0; i < objs.length; i++){
					if(objs[i].value != 0 && objs[i].checked)sign = sign + 1;
				}
				if(isExpUser == '1' || sign <= notUseCustomerNum){
					document.exceptionCustomerForm.action = "./exceptionCustomer.do?action=salePersonToCustomer&salePersonId="+salePersonId;
					document.exceptionCustomerForm.target = "main";
					document.exceptionCustomerForm.submit();
				}else{
					alert("<fmt:message key='exception.message.overstep'/>"+notUseCustomerNum+"<fmt:message key='customer.message.num'/>");
				}
			}
		}
	}
	
	function moveDialog(){
		var url = "./exceptionCustomer.do?action=preSelectMoveTarget";
		var dlgParam = "dialogHeight:300px;dialogWidth:300px;dialogTop:300px;dialogLeft:400px;status:no;help:no;scrollbars:yes;";
		if(checkForm()){
			var rt = window.showModalDialog(url,"",dlgParam);
			if(rt != undefined && rt != ""){			
				//根据从子窗口得到转移目标id
				var notUseCustomerNum = "<c:out value='${customerLimitForm.untappedCustomerNum}'/>";
				var isExpUser = "<c:out value='${isExpUser}'/>";
				var objs = document.getElementsByName("id");
				var sign = 0;
				for(var i = 0; i < objs.length; i++){
					if(objs[i].value != 0 && objs[i].checked)sign = sign + 1;
				}
				if(isExpUser == '1' || rt != '1' || (rt == '1' && sign <= notUseCustomerNum)){
					document.exceptionCustomerForm.action = "./exceptionCustomer.do?action=moveCustomerToTarget&isTarget="+rt;
					document.exceptionCustomerForm.target = "main";
					document.exceptionCustomerForm.submit();
				}else if(rt == '1' && sign > notUseCustomerNum){
					alert("<fmt:message key='exception.message.overstep2'/>"+notUseCustomerNum+"<fmt:message key='customer.message.num'/>");
				}
			}
		}
	}
	
	function searchCustomer(){
		var salePerson = document.getElementById("salePerson");
		if(salePerson.value == ""){
			alert("<fmt:message key='exception.message.salePerson'/>");
		}else{
			document.getElementById("sFlag").value = "1";
			document.exceptionCustomerForm.action = "./exceptionCustomer.do";
			document.exceptionCustomerForm.target = "main";
			document.exceptionCustomerForm.submit();
		}
	}
	
	function pageCustomer(flag){
		document.exceptionCustomerForm.action = "./exceptionCustomer.do?action=display&flag="+flag;
		document.exceptionCustomerForm.target = "main";
		document.exceptionCustomerForm.submit();
	}
	
	function initPage(){
		if("<c:out value='${result}'/>" == 1){
			alert("<fmt:message key='exception.message.setSuccess'/>");
		}else if("<c:out value='${result}'/>" == 2){
			alert("<fmt:message key='exception.message.moveSuccess'/>");
		}
		
		if("<c:out value='${deleteResult}'/>" == 1){
			alert("<fmt:message key='common.message.deleteSuccess'/>");
		}
	}
-->
</script>
</head>
<body onload="initPage()">
<form name="exceptionCustomerForm" action="" method="post">
	<table class="table_frame">
		<tr>
			<td>
				<table class="table_title1">
					<tr>
						<td class="title_lab" colspan="2">异动客户</td>
					</tr>
					<tr>
						<td valign="bottom" class="a_tools" style="padding-left: 3px;">销售代表：
							<input id="salePerson" name="salePerson" class="input_query" type="text" value="${salePerson}"/>
							<input id="sFlag" name="sFlag" type="hidden" value="${sFlag}"/>
							<a class="search" href="javascript:searchCustomer();" target="main" hidefocus="true">查询</a>
							|
							<c:if test="${isSettingSalePerson == 1}">
							<a class="ssaleperson" href="javascript:personDialog();" title="<fmt:message key='exception.button.setPerson'/>" hidefocus="true"><fmt:message key='exception.button.setPerson'/></a>
							</c:if>
							<c:if test="${isMoveCustomer == 1}">
							<a class="move" href="javascript:moveDialog();" title="<fmt:message key='exception.button.move'/>" hidefocus="true"><fmt:message key='exception.button.move'/></a>
							</c:if>
						</td>
						<td></td>
					</tr>
					<tr><td height="2" colspan="2"></td></tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table class="table_title2">
					<tr>
						<td class="title_lab">异动客户</td>
						<!-- 
						<td align="left" valign="bottom">
							<table class="table" style="font-weight: bold;">
								<tr>
									<td align="left">&nbsp;
										<img src="./images/limit1.jpg" style="vertical-align: middle;"/>&nbsp;<font class="font_bule">已保护</font>：
										<font class="font_orange">${customerLimitForm.currentCustomerNum}</font>&nbsp;<fmt:message key='common.lable.a'/>&nbsp;&nbsp;
										<img src="./images/limit2.jpg" style="vertical-align: middle;"/>&nbsp;<font class="font_bule">保护上限</font>：
										<c:choose>
											<c:when test="${isExpUser == 1}"><font class="font_orange">无限制</font></c:when>
											<c:otherwise><font class="font_orange">${customerLimitForm.totalCustomerLimit}</font>&nbsp;<fmt:message key='common.lable.a'/></c:otherwise>
										</c:choose>&nbsp;&nbsp;
										<img src="./images/limit3.jpg" style="vertical-align: middle;"/>&nbsp;<font class="font_bule">可保护</font>：
										<c:choose>
											<c:when test="${isExpUser == 1}"><font class="font_orange">无限制</font></c:when>
											<c:otherwise><font class="font_orange">${customerLimitForm.untappedCustomerNum}</font>&nbsp;<fmt:message key='common.lable.a'/></c:otherwise>
										</c:choose>
									</td>
								</tr>
							</table>
						</td>
						 -->
						<td align="right" valign="">
							<!-- page -->
							<table class="table_page2">
								<tr>
									<td valign="bottom">
										<img src="./images/frist.bmp" onclick="pageCustomer(1)" alt="首页" style="vertical-align: middle;cursor: hand;">
										<img src="./images/last.bmp" onclick="pageCustomer(2)" alt="上一页" style="vertical-align: middle;cursor: hand;">&nbsp;
										<font color="red">${currentPage}</font>/${totalPages}&nbsp;<fmt:message key='common.page'/>&nbsp;
										<img src="./images/next.bmp" onclick="pageCustomer(3)" alt="下一页" style="vertical-align: middle;cursor: hand;">
										<img src="./images/end.bmp" onclick="pageCustomer(4)" alt="末页" style="vertical-align: middle;cursor: hand;">
										共&nbsp;&nbsp;${totalRows}&nbsp;<fmt:message key='common.page.totalRow'/>&nbsp;&nbsp;&nbsp;
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr><td colspan="2" height="2"></td></tr>
					<tr>
						<td colspan="2" valign="top">
							<table class="table">
								<tr>
									<td valign="top">
										<!-- 
										<div style="width:800px;height:100%;overflow-x: scroll;overflow-y: hidden;">
										 -->
										<table class="table_style">
											<tr>
												<td class="title" width="8"></td>
												<td class="title" width="30"><input id="id" name="id" type="checkbox" value="0" onclick="checkAll('id')"/></td>
												<td class="title"><fmt:message key='customer.lable.customerName'/></td>
												<td class="title" width="12%"><fmt:message key='customer.lable.lastlink'/></td>
												<td class="title" width="12%"><fmt:message key='myRecycle.lable.saleStage'/></td>
												<td class="title" width="12%"><fmt:message key='customer.lable.saleperson'/></td>
												<td class="title" width="12%"><fmt:message key='exception.lable.reason'/></td>
											</tr>
											<c:forEach var="customer" items="${customers}">
											<tr onmouseover="onmousemoveChange(this,'img${customer.id}')" onmouseout="onmouseoutChange(this,'img${customer.id}')">
												<td height="16" width="8" align="right"><img id="img${customer.id}" src="./images/table_sign2.bmp"></td>
												<td align="center"><input id="id" name="id" type="checkbox" value="${customer.id}"/></td>
												<td align="left"><a href="./customerManage.do?action=customerDetail&customerId=${customer.id}&sign=31" target="main">${customer.customerName}</a></td>
												<td><fmt:formatDate value="${customer.lastLink}" pattern="yyyy-MM-dd"/></td>
												<td>${customer.saleStage}</td>
												<td>${customer.salePerson}</td>
												<td>
												<c:choose>
													<c:when test="${customer.exceptionReason == '1'}"><fmt:message key='exception.select.overdue'/></c:when>
													<c:when test="${customer.exceptionReason == '2'}"><fmt:message key='exception.select.dept'/></c:when>
													<c:when test="${customer.exceptionReason == '3'}"><fmt:message key='exception.select.leave'/></c:when>
													<c:when test="${customer.exceptionReason == '4'}"><fmt:message key='exception.select.other'/></c:when>
													<c:otherwise></c:otherwise>
												</c:choose>
												</td>
											</tr>
											</c:forEach>
										</table>
										<!-- 
										</div>
										 -->
									</td>
								</tr>
								<tr>
									<td align="left" valign="bottom">
										<!-- page -->
										<table id="tp" class="table_page">
											<tr>
												<td>&nbsp;&nbsp;
													<img src="./images/frist.bmp" onclick="pageCustomer(1)" alt="首页" style="vertical-align: middle;cursor: hand;">
													<img src="./images/last.bmp" onclick="pageCustomer(2)" alt="上一页" style="vertical-align: middle;cursor: hand;">&nbsp;
													<font color="red">${currentPage}</font>/${totalPages}&nbsp;<fmt:message key='common.page'/>&nbsp;
													<img src="./images/next.bmp" onclick="pageCustomer(3)" alt="下一页" style="vertical-align: middle;cursor: hand;">
													<img src="./images/end.bmp" onclick="pageCustomer(4)" alt="末页" style="vertical-align: middle;cursor: hand;">
													共&nbsp;&nbsp;${totalRows}&nbsp;<fmt:message key='common.page.totalRow'/>
												</td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</form>
</body>
</html>